//
//  ClubMyselfInfoView.swift
//  77Club
//
//  Created by Apple on 2024/9/18.
//

import UIKit

class ClubMyselfInfoView: UIView {
    
    private let shadowView = c_make_ex(UIView.self)
        .bgColor(.black.alpha(0.6)).end()
    private let bgImageView = c_make_ex(UIImageView.self)
        .mode(.scaleAspectFill).image("Mine_info_bg").end()
    private let backButton = c_make_ex(UIButton.self)
        .image("Common_whiteBack").end()
    private let sureButton = c_make_ex(UIButton.self)
        .image("Mine_sure").end()
    let iconImageView = c_make_ex(UIImageView.self)
        .mode(.scaleAspectFill).corner(27).end()
    private let circleView = c_make_ex(UIButton.self)
        .bgColor(.clear).corner(32).border(.white.alpha(0.2), width: 2).end()
    private let cameraImageV = c_make_ex(UIImageView.self)
        .image("Mine_info_camera").end()
    
    var backBlock: (() -> Void)?
    var saveBlock: (() -> Void)?
    var iconBlock: (() -> Void)?
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        backgroundColor = .clear
        
        subviews{
            bgImageView.subviews{
                shadowView
            }
            backButton
            sureButton
            iconImageView
            circleView
            cameraImageV
        }
        
        bgImageView.fillContainer()
        shadowView.fillContainer()
        backButton.leading(0).top(.statusHeight).width(56).height(44)
        sureButton.trailing(0).top(.statusHeight).width(88).height(44)
        circleView.top(.navi_height + 45).size(64).centerHorizontally()
        iconImageView.size(54).centerHorizontally()
        iconImageView.CenterY == circleView.CenterY
        cameraImageV.size(24)
        cameraImageV.Trailing == circleView.Trailing
        cameraImageV.Bottom == circleView.Bottom
        
        bgImageView.layer.masksToBounds = true
        circleView.isUserInteractionEnabled = true
        let tapG = UITapGestureRecognizer(target: self, action: #selector(clickIconImageView))
        backButton.addTarget(self, action: #selector(clickBackButton), for: .touchUpInside)
        sureButton.addTarget(self, action: #selector(clickSaveButton), for: .touchUpInside)
        circleView.addGestureRecognizer(tapG)
    }
    
    @objc private func clickBackButton(){
        backBlock?()
    }
    
    @objc private func clickSaveButton(){
        saveBlock?()
    }
    
    @objc private func clickIconImageView(){
        iconBlock?()
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        
        bgImageView.rae.corner(12, corners: [.layerMaxXMaxYCorner,.layerMinXMaxYCorner])
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}


class ClubMyselfInfoNickNameView: UIView, UITextFieldDelegate {
    
    private let bgView = c_make_ex(UIView.self)
        .bgColor(.white).corner(8).end()
    private let titleLabel = c_make_ex(UILabel.self)
        .text("我的昵称").color("#7B7D80").font(12.font_medium).end()
    let nameTextField = c_make_ex(UITextField.self)
        .color("#2E3033").font(15.font_medium).end()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        backgroundColor = .clear
        
        subviews{
            bgView.subviews{
                titleLabel
                nameTextField
            }
        }
        
        nameTextField.delegate = self
        bgView.leading(12.0.Scale).trailing(12.0.Scale).top(0).bottom(0)
        titleLabel.leading(16.0.Scale).top(16.0.Scale)
        nameTextField.leading(16.0.Scale).bottom(12.0.Scale).trailing(12.0.Scale)
    }
    
    // 限制输入字符数量
    func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
        let currentText = textField.text ?? ""
        let prospectiveText = (currentText as NSString).replacingCharacters(in: range, with: string)

        // 限制字数为10
        return prospectiveText.count <= 10
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}

class ClubMyselfInfoAccountView: UIView {
    
    private let bgView = c_make_ex(UIView.self)
        .bgColor(.white).corner(8).end()
    private let titleLabel = c_make_ex(UILabel.self)
        .text("我的账号").color("#7B7D80").font(12.font_medium).end()
    let valueLabel = c_make_ex(UILabel.self)
        .color("#2E3033").font(15.font_medium).end()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        backgroundColor = .clear
        
        subviews{
            bgView.subviews{
                titleLabel
                valueLabel
            }
        }
        
        bgView.leading(12.0.Scale).trailing(12.0.Scale).top(0).bottom(0)
        titleLabel.leading(16.0.Scale).top(16.0.Scale)
        valueLabel.leading(16.0.Scale).bottom(12.0.Scale)
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}


class ClubMyselfInfoBirthdayView: UIView {
    
    private let bgView = c_make_ex(UIView.self)
        .bgColor(.white).corner(8).end()
    private let titleLabel = c_make_ex(UILabel.self)
        .text("出生日期").color("#7B7D80").font(12.font_medium).end()
    let valueLabel = c_make_ex(UILabel.self)
        .color("#E57617").font(15.font_medium).end()
    let rightImageV = c_make_ex(UIImageView.self)
        .mode(.scaleAspectFill).image("Mine_settings_next").end()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        backgroundColor = .clear
        
        subviews{
            bgView.subviews{
                titleLabel
                valueLabel
                rightImageV
            }
        }
        
        bgView.leading(12.0.Scale).trailing(12.0.Scale).top(0).bottom(0)
        titleLabel.leading(16.0.Scale).top(16.0.Scale)
        valueLabel.leading(16.0.Scale).bottom(12.0.Scale)
        rightImageV.trailing(16.0.Scale).size(20.0.Scale).centerVertically()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}

class ClubMyselfInfoAddressView: UIView {
    
    private let bgView = c_make_ex(UIView.self)
        .bgColor(.white).corner(8).end()
    private let titleLabel = c_make_ex(UILabel.self)
        .text("地址管理").color("#7B7D80").font(12.font_medium).end()
    let valueLabel = c_make_ex(UILabel.self)
        .color("#2E3033").font(15.font_medium).text("地址管理").end()
    private let rightImageV = c_make_ex(UIImageView.self)
        .mode(.scaleAspectFill).image("Mine_settings_next").end()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        backgroundColor = .clear
        
        subviews{
            bgView.subviews{
                titleLabel
                valueLabel
                rightImageV
            }
        }
        
        bgView.leading(12.0.Scale).trailing(12.0.Scale).top(0).bottom(0)
        titleLabel.leading(16.0.Scale).top(16.0.Scale)
        valueLabel.leading(16.0.Scale).bottom(12.0.Scale)
        rightImageV.trailing(16.0.Scale).size(20.0.Scale).centerVertically()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}


class ClubMyselfInfoDelView: UIView {
    
    private let bgView = c_make_ex(UIView.self)
        .bgColor(.white).corner(8).end()
    private let titleLabel = c_make_ex(UILabel.self)
        .text("账号注销").color("#2E3033").font(15.font_medium).end()
    private let rightImageV = c_make_ex(UIImageView.self)
        .mode(.scaleAspectFill).image("Mine_settings_next").end()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        backgroundColor = .clear
        
        subviews{
            bgView.subviews{
                titleLabel
                rightImageV
            }
        }
        
        bgView.leading(12.0.Scale).trailing(12.0.Scale).top(0).bottom(0)
        titleLabel.leading(16.0.Scale).centerVertically()
        rightImageV.trailing(16.0.Scale).size(20.0.Scale).centerVertically()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}
